package misp_backend.controller;

import misp_backend.config.AjaxResult;
import misp_backend.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {
    @Autowired
    private StatisticsService statisticsService;

    @GetMapping("/category")
    public AjaxResult categorySales(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end) {
        return AjaxResult.success(statisticsService.getCategorySales(start, end));
    }

    @GetMapping("/monthly")
    public AjaxResult monthlySales(@RequestParam Integer year) {
        return AjaxResult.success(statisticsService.getMonthlySales(year));
    }

}
